package androidx.transition;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.util.AttributeSet;
import o.fw;
import o.fx;
import o.ns;
import org.xmlpull.v1.XmlPullParser;

public class PatternPathMotion extends PathMotion {
    private final Path ˊ = new Path();
    private final Matrix ˋ = new Matrix();
    private Path ˎ;

    public PatternPathMotion() {
        this.ˊ.lineTo(1.0f, 0.0f);
        this.ˎ = this.ˊ;
    }

    public PatternPathMotion(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, ns.ˏॱ);
        try {
            String ˏ = fx.ˏ(obtainStyledAttributes, (XmlPullParser) attributeSet, "patternPathData", 0);
            if (ˏ == null) {
                throw new RuntimeException("pathData must be supplied for patternPathMotion");
            }
            ˎ(fw.ˊ(ˏ));
        } finally {
            obtainStyledAttributes.recycle();
        }
    }

    public void ˎ(Path path) {
        PathMeasure pathMeasure = new PathMeasure(path, false);
        float[] fArr = new float[2];
        pathMeasure.getPosTan(pathMeasure.getLength(), fArr, null);
        float f = fArr[0];
        float f2 = fArr[1];
        pathMeasure.getPosTan(0.0f, fArr, null);
        float f3 = fArr[0];
        float f4 = fArr[1];
        if (f3 == f && f4 == f2) {
            throw new IllegalArgumentException("pattern must not end at the starting point");
        }
        this.ˋ.setTranslate(-f3, -f4);
        f3 = f - f3;
        f = f2 - f4;
        f4 = 1.0f / ˏ(f3, f);
        this.ˋ.postScale(f4, f4);
        this.ˋ.postRotate((float) Math.toDegrees(-Math.atan2((double) f, (double) f3)));
        path.transform(this.ˋ, this.ˊ);
        this.ˎ = path;
    }

    public Path ˏ(float f, float f2, float f3, float f4) {
        float f5 = f3 - f;
        float f6 = f4 - f2;
        float ˏ = ˏ(f5, f6);
        double atan2 = Math.atan2((double) f6, (double) f5);
        this.ˋ.setScale(ˏ, ˏ);
        this.ˋ.postRotate((float) Math.toDegrees(atan2));
        this.ˋ.postTranslate(f, f2);
        Path path = new Path();
        this.ˊ.transform(this.ˋ, path);
        return path;
    }

    private static float ˏ(float f, float f2) {
        return (float) Math.sqrt((double) ((f * f) + (f2 * f2)));
    }
}
